<?php

namespace Modules\Edu\Entities;

use App\Models\Traits\Site;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;


class Comment extends Model
{
    use Site, LogsActivity;

    protected $table = 'edu_comment';
    protected $fillable = ['reply_user_id', 'content', 'favour_count', 'site_id', 'user_id'];
    //LogsActivity options
    protected static $logName = 'comment';
    protected static $recordEvents = ['created'];

    public function commentable()
    {
        return $this->morphto('comment');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function getHtmlAttribute()
    {
        //html转markdown转高亮
        $Parsedown = new \Parsedown();
//        dd($Parsedown->text($this->content));
        return clean($Parsedown->text($this->content));
    }

    public function replyUser()
    {
        return $this->belongsTo(User::class, 'reply_user_id');
    }

}
